﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Sherbanov.Converters
{
        public  class b2gbConverter : IValueConverter
        {

            public object Convert(object value, Type targetType,
                                  object parameter, System.Globalization.CultureInfo culture)
            {
                string[] units = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
                double size = (long)System.Convert.ToInt64(value);
                int unit = 0;

                while (size >= 1024)
                {
                    size /= 1024;
                    ++unit;
                }
                return String.Format("{0:0.#} {1}", size, units[unit]);

            }

            public object ConvertBack(object value, Type targetType,
                                      object parameter, System.Globalization.CultureInfo culture)
            {
                return null;
            }
        }


    
}
